package com.leeon.container;

import typeinfo.pets.*;

import java.util.*;

import static net.mindview.util.Print.print;

public class ListFeaturesInteger {

    public static List<Integer> generatorList(int size){
        Random random = new Random();
        List<Integer> list = new ArrayList<Integer>(size);
        for (int i = 0; i < size; i++) {
            list.add(random.nextInt(10));
        }
        return list;
    }

    public static Integer generatorInteger(){
        Random random = new Random();
        return random.nextInt(10);
    }

    public static void main(String[] args){
        Random random = new Random(47);
        List<Integer> ints = generatorList(10);
        System.out.println("1:" + ints);
        Integer h = generatorInteger();
        ints.add(h);
        System.out.println("2:" + ints);
        System.out.println("3:" + ints.contains(h));
        ints.remove(h);
        Integer p = ints.get(2);
        System.out.println("4" + p + " " + ints.indexOf(p));
        Integer cymric = generatorInteger();
        System.out.println("5: " + ints.indexOf(cymric));
        System.out.println("6: " + ints.remove(cymric));
        System.out.println("7: " + ints.remove(p));
        System.out.println("8: " + ints);
        ints.add(3,generatorInteger());
        System.out.println("9: " + ints);
        List<Integer> sub = ints.subList(1,4);
        System.out.println("sublist : " + sub);
        System.out.println("10: " + ints.containsAll(sub));
        Collections.sort(sub);
        System.out.println("sorted sublist: " + sub);
        System.out.println("11: " + ints.containsAll(sub));
        Collections.shuffle(sub,random);
        print("shuffled sublist : " + sub);
        print("12 : " + ints.containsAll(sub));
        List<Integer> copy = new ArrayList<Integer>();
        sub = Arrays.asList(ints.get(1),ints.get(4));
        print("sub: " + sub);
        copy.retainAll(sub);
        print("13: " + copy);
        copy = new ArrayList<Integer>(ints);
        print("13-1 : " + copy);
        copy.remove(2);
        print("14 : " + copy);
        print("14-1 : " + sub);
        copy.removeAll(sub);
        print("15: " + copy);
        copy.set(1,generatorInteger());
        print("16: " + copy);
        copy.addAll(2,sub);
        print("17: " + copy);
        print("18: " + ints.isEmpty());
        ints.clear();
        print("19: " + ints);
        print("20: " + ints.isEmpty());
        ints.addAll(generatorList(5));
        print("21: " + ints);
        Object[] o = ints.toArray();
        print("22: " + o[3]);
        Integer[] pa = ints.toArray(new Integer[2]);
        print("23: "+ pa[3]);
    }
}
